package com.iwhalecloud.bss.kite.cucc.web.service.accept.handler.module;

import com.iwhalecloud.bss.kite.client.api.reception.IServiceOfferService;
import com.iwhalecloud.bss.kite.client.dto.DataResult;
import com.iwhalecloud.bss.kite.client.dto.inst.InstAttrDTO;
import com.iwhalecloud.bss.kite.client.vo.scene.CommonAttrVO;
import com.iwhalecloud.bss.kite.client.vo.scene.ProdAttrModuleVO;
import com.iwhalecloud.bss.kite.client.vo.scene.ProdAttrVO;
import com.iwhalecloud.bss.kite.client.vo.scene.ProdRoleModuleVO;
import com.iwhalecloud.bss.kite.client.vo.scene.ProductModuleVO;
import com.iwhalecloud.bss.kite.client.vo.scene.transference.TransferenceVO;
import com.iwhalecloud.bss.kite.client.vo.spec.ServiceOfferTypeVO;
import com.iwhalecloud.bss.kite.client.vo.spec.ServiceOfferVO;
import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.constant.ServiceOfferConsts;
import com.iwhalecloud.bss.kite.common.util.KiteBeanUtils;
import com.iwhalecloud.bss.kite.common.util.KiteListUtils;
import com.iwhalecloud.bss.kite.common.util.KiteObjectUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.client.api.attr.ILocalQueryScenePersonInfoService;
import com.iwhalecloud.bss.kite.cucc.client.api.order.IBusinessChangeService;
import com.iwhalecloud.bss.kite.cucc.client.vo.scene.CuccProdAttrVO;
import com.iwhalecloud.bss.kite.cucc.client.vo.scene.GoodsModifyInfoVO;
import com.iwhalecloud.bss.kite.cucc.client.vo.scene.CuccServiceOfferVo;
import com.iwhalecloud.bss.kite.cucc.client.vo.scene.CuccServiceOfferTypeVO;
import com.iwhalecloud.bss.kite.cucc.client.vo.scene.ReCommitInfoVO;
import com.iwhalecloud.bss.kite.cucc.client.vo.scene.SceneNewOfferSeneVO;
import com.iwhalecloud.bss.kite.cucc.client.vo.scene.ServiceOfferInfoModuleVO;
import com.iwhalecloud.bss.kite.cucc.client.vo.scene.TransferInfoVO;
import com.iwhalecloud.bss.kite.cucc.common.constant.CuccServiceOfferConsts;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalServiceOfferConsts;
import com.iwhalecloud.bss.kite.cucc.common.util.AssemblyAttrDtoUtils;
import com.iwhalecloud.bss.kite.cucc.service.scene.attr.CuccOperateInstAttrService;
import com.iwhalecloud.bss.kite.cucc.web.service.accept.handler.attr.IPersonAttrDealService;
import com.iwhalecloud.bss.kite.dataservice.cache.OfferCache;
import com.iwhalecloud.bss.kite.manager.api.IOperateSceneInstService;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteProdInst;
import com.iwhalecloud.bss.kite.manager.inst.change.KiteInstChange;
import com.iwhalecloud.bss.kite.web.context.KiteWebContext;
import com.iwhalecloud.bss.kite.web.service.accept.bo.AcceptContext;
import com.iwhalecloud.bss.kite.web.service.accept.bo.SceneModule;
import com.iwhalecloud.bss.kite.web.service.accept.handler.module.AbstractModuleHandler;
import com.iwhalecloud.bss.kite.web.service.accept.service.SceneModuleCache;
import com.ztesoft.bss.common.util.SpringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 *
 */
@Service
public class ReCommitInfoModuleHandler extends AbstractModuleHandler {

    @Autowired
    private IQuerySceneInstService querySceneInstService;

    @Autowired
    private ILocalQueryScenePersonInfoService queryScenePersonService;

    @Autowired
    private IPersonAttrDealService personAttrDealService;

    @Autowired
    private IBusinessChangeService businessChangeService;

    private static final String RATESCHANGE_SERVICCEOFFER = "1009"; //资费变更业务

    @Autowired
    private IServiceOfferService serviceOfferService;

    @Autowired
    private CuccOperateInstAttrService cuccOperateInstAttrService;

    @Autowired
    private IOperateSceneInstService operateSceneInstService;

    private static final String INSTANCETYPE = "10C";

    private static final String SOURCE = "0";

    @Override
    public List<ReCommitInfoVO> execute(AcceptContext context, SceneModule sceneModule) {

        ReCommitInfoVO reCommitInfoVO = new ReCommitInfoVO();
        ServiceOfferInfoModuleVO serviceOfferInfoModuleVOs = serviceExecute(context, sceneModule);
        serviceOfferInfoModuleVOs.setIsEdit("F");
        serviceOfferInfoModuleVOs.setIsShow("T");
        serviceOfferInfoModuleVOs.setLayoutPage("ServiceOfferInfo");
        serviceOfferInfoModuleVOs.setModuleName("操作类型");
        serviceOfferInfoModuleVOs.setOrderId("1");
        reCommitInfoVO.setServiceOfferInfoModuleVO(serviceOfferInfoModuleVOs);

        List<String> serviceOfferIdList = querySceneInstService //获取页面勾选的操作类型
            .getExtParameterValue(context.getSceneVo().getSceneInstId(), "BUSI_CHANGE_SERVICEOFFERID");
        if (KiteListUtils.isNotEmpty(serviceOfferIdList) && serviceOfferIdList.size() == 1 && serviceOfferIdList
            .contains(LocalServiceOfferConsts.SERVICE_OFFER_TRANSFER_CUST)) {
            TransferInfoExecute(context, sceneModule, reCommitInfoVO);
        }
        else {
            GoodsModifyInfoVO goodsModifyInfoVOs = modifyInfoExecute(context, sceneModule);
            goodsModifyInfoVOs.setIsEdit("T");
            goodsModifyInfoVOs.setIsShow("T");
            goodsModifyInfoVOs.setOrderId("2");
            goodsModifyInfoVOs.setLayoutPage("ModifyInfo");
            goodsModifyInfoVOs.setModuleName("业务变更信息");
            reCommitInfoVO.setGoodsModifyInfoVO(goodsModifyInfoVOs);

            TransferInfoExecute(context, sceneModule, reCommitInfoVO);
        }
        SceneNewOfferSeneVO sceneNewOfferSeneVO = (SceneNewOfferSeneVO) context.getSceneVo();
        //如果是业务变更的质检环节,则只返回业务变更信息,且不可编辑
        if (!KiteObjectUtils.isEmpty(context.getAcceptRequest()) && KiteStringUtils
            .equalsAny(context.getAcceptRequest().getServiceOfferId(), LocalServiceOfferConsts.SERVICE_OFFER_QC)) {
            reCommitInfoVO.setModuleName("业务变更信息");
        }
        sceneNewOfferSeneVO.setReCommitInfoVO(reCommitInfoVO);
        return Collections.singletonList(reCommitInfoVO);
    }

    @Override
    public List<ReCommitInfoVO> previewSceneVo(AcceptContext context, SceneModule sceneModule) {
        ReCommitInfoVO reCommitInfoVO = new ReCommitInfoVO();
        GoodsModifyInfoVO goodsModifyInfoVOs = modifyInfoPreviewSceneVo(context, sceneModule);
        goodsModifyInfoVOs.setIsEdit("T");
        goodsModifyInfoVOs.setIsShow("T");
        goodsModifyInfoVOs.setLayoutPage("ModifyInfo");
        goodsModifyInfoVOs.setModuleName("业务变更信息");
        goodsModifyInfoVOs.setOrderId("2");
        ServiceOfferInfoModuleVO serviceOfferInfoModuleVOs = serviceReviewSceneVo(context, sceneModule);
        serviceOfferInfoModuleVOs.setIsEdit("F");
        serviceOfferInfoModuleVOs.setIsShow("T");
        serviceOfferInfoModuleVOs.setLayoutPage("ServiceOfferInfo");
        serviceOfferInfoModuleVOs.setModuleName("操作类型");
        serviceOfferInfoModuleVOs.setOrderId("1");
        reCommitInfoVO.setServiceOfferInfoModuleVO(serviceOfferInfoModuleVOs);
        reCommitInfoVO.setGoodsModifyInfoVO(goodsModifyInfoVOs);
        SceneNewOfferSeneVO sceneNewOfferSeneVO = (SceneNewOfferSeneVO) context.getSceneVo();
        sceneNewOfferSeneVO.setReCommitInfoVO(reCommitInfoVO);
        return Collections.singletonList(reCommitInfoVO);
    }

    public GoodsModifyInfoVO modifyInfoExecute(AcceptContext context, SceneModule sceneModule) {
        String offerId = context.getAcceptRequest().getOfferId();
        String sceneInstId = context.getSceneVo().getSceneInstId();
        List<ProductModuleVO> productModule = new ArrayList<>(); //产品信息
        String custId = context.getAcceptRequest().getCustId();
        //获取所有的操作类型
        List<CuccServiceOfferVo> serviceOfferVOs = new ArrayList<>();
        SceneNewOfferSeneVO sceneNewOfferSeneVO = (SceneNewOfferSeneVO) context.getSceneVo();
        ServiceOfferInfoModuleVO serviceOfferInfoModuleVO = sceneNewOfferSeneVO.getServiceOfferInfoModuleVO();
        List<CuccServiceOfferTypeVO> serviceOfferTypeVOs = serviceOfferInfoModuleVO.getServiceOfferTypes();
        for (int i = 0; i < serviceOfferTypeVOs.size(); i++) {
            CuccServiceOfferTypeVO cuccServiceOfferTypeVO = serviceOfferTypeVOs.get(i);
            serviceOfferVOs.addAll(cuccServiceOfferTypeVO.getServiceOfferViews());
        }

        String accNum = "";
        List<String> serviceOfferIdList = querySceneInstService //获取页面勾选的操作类型
            .getExtParameterValue(context.getSceneVo().getSceneInstId(), "BUSI_CHANGE_SERVICEOFFERID");
        List<KiteProdInst> kiteProdInsts = querySceneInstService.listProdInsts(sceneInstId);
        // 如果当前只勾选资费变更,则业务变更模块只返回商品信息和资费变更信息
        boolean ratesChangeFlag = false;
        if (KiteListUtils.isNotEmpty(serviceOfferIdList) && serviceOfferIdList.size() == 1 && serviceOfferIdList
            .contains(RATESCHANGE_SERVICCEOFFER)) {
            ratesChangeFlag = true;
        }
        if (KiteListUtils.isNotEmpty(kiteProdInsts) && !ratesChangeFlag) {
            kiteProdInsts.forEach(kiteProdInst -> {
                ProductModuleVO productModuleVO = businessChangeService.genProductVO(kiteProdInst.getProdId());
                ProdRoleModuleVO prodRoleVO = businessChangeService.genProductRoleVO(kiteProdInst);
                ProdAttrModuleVO prodAttrModule = new ProdAttrModuleVO();
                List<ProdAttrVO> prodAttrList = new ArrayList();
                if (KiteListUtils.isNotEmpty(serviceOfferIdList)) {
                    for (String serviceOfferId : serviceOfferIdList) {
                        prodAttrModule = businessChangeService
                            .dealProdAttrList(sceneInstId, custId, kiteProdInst, serviceOfferId, prodAttrModule);
                        if (ServiceOfferConsts.SERVICE_OFFER_MODIFY.equals(serviceOfferId)
                            || CuccServiceOfferConsts.SERVICE_OFFER_OTHER_BUSINESS_CHANGE.equals(serviceOfferId)
                            || CuccServiceOfferConsts.SERVICE_OFFER_BUSINESS_CHANGE.equals(serviceOfferId)) {
                            List<ProdAttrVO> list = new ArrayList();
                            if (KiteListUtils.isNotEmpty(serviceOfferVOs)) {
                                for (CuccServiceOfferVo vo : serviceOfferVOs) {
                                    String servOfferId = vo.getServiceOfferId();
                                    if (!KiteStringUtils
                                        .isEqual(CuccServiceOfferConsts.SERVICE_OFFER_OTHER_BUSINESS_CHANGE,
                                            servOfferId)) {
                                        ProdAttrModuleVO cProdAttrModule = cuccOperateInstAttrService
                                            .processAttrs(sceneInstId, custId, kiteProdInst.getProdInstId(),
                                                servOfferId, kiteProdInst.getProdId());
                                        list.addAll(cProdAttrModule.getProdAttrList());
                                    }
                                }
                                if (KiteListUtils.isNotEmpty(list)) {
                                    list = businessChangeService.removeProdAttrVO(list); // 过滤去重
                                    prodAttrList = prodAttrModule.getProdAttrList();
                                    for (ProdAttrVO vo : list) {
                                        Iterator<ProdAttrVO> iterator = prodAttrList.iterator();
                                        while (iterator.hasNext()) {
                                            ProdAttrVO next = iterator.next();
                                            if (vo.getAttrId().equals(next.getAttrId())) {
                                                iterator.remove();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (KiteListUtils.isNotEmpty(prodAttrModule.getProdAttrList())) {
                            prodAttrList.addAll(prodAttrModule.getProdAttrList());
                        }
                    }
                    List<ProdAttrVO> prodAttrVOList = businessChangeService.removeProdAttrVO(prodAttrList); // 过滤去重
                    prodAttrModule.setProdAttrList(prodAttrVOList);
                }
                else {
                    String serviceOfferId = context.getAcceptRequest().getServiceOfferId();
                    prodAttrModule = businessChangeService
                        .dealProdAttrList(sceneInstId, custId, kiteProdInst, serviceOfferId, prodAttrModule);
                }
                prodRoleVO.setProdAttr(prodAttrModule);
                productModuleVO.getProdRole().add(prodRoleVO);
                productModule.add(productModuleVO);
            });
            accNum = kiteProdInsts.get(0).getAccNum();
        }

        List<CommonAttrVO> goodsInfo = this.getGoodsDisplayInfoAttrs(context, offerId, accNum);
        GoodsModifyInfoVO modifyInfo = new GoodsModifyInfoVO();
        modifyInfo.setGoodsInfoAttr(goodsInfo);

        String serviceOfferId = querySceneInstService.getSceneInst(sceneInstId).getServiceOfferId();

        boolean showPayAddtionFlag = false; // 控制业务变更模块是否需要展示资费信息

        if (KiteListUtils.isEmpty(serviceOfferIdList) && ServiceOfferConsts.SERVICE_OFFER_MODIFY
            .equals(serviceOfferId)) {
            showPayAddtionFlag = true;
        }
        else if (KiteListUtils.isNotEmpty(serviceOfferIdList) && (serviceOfferIdList.contains(RATESCHANGE_SERVICCEOFFER)
            || serviceOfferIdList.contains(CuccServiceOfferConsts.SERVICE_OFFER_BUSINESS_CHANGE))) {
            showPayAddtionFlag = true;
        }
        if (showPayAddtionFlag) {
            SceneModule module = SceneModuleCache.get("97", sceneNewOfferSeneVO.getTemplateId());
            OptionalAdditionalOfferModuleHandler handler = SpringUtil
                .getBean(OptionalAdditionalOfferModuleHandler.class);
//            OptionalAdditionalOfferModuleVO optionalAdditionalOfferModuleVO = handler
//                .getOptionalAdditionalOfferModuleVO(context);
//            if (Objects.nonNull(module)) {
//                KiteBeanUtils.copyProperties(module.getKiteModule(), optionalAdditionalOfferModuleVO);
//            }
//            else {
//                optionalAdditionalOfferModuleVO.setIsShow("T");
//                optionalAdditionalOfferModuleVO.setModuleName("资费信息");
//            }
//            optionalAdditionalOfferModuleVO.setIsEdit("T");
//            String oStr = JSON.toJSONString(optionalAdditionalOfferModuleVO);
//            OptionalAdditionalOfferModuleVO vo = JsonUtils.parseObject(oStr, OptionalAdditionalOfferModuleVO.class);
//            modifyInfo.setAdditionalOffers(vo);
        }
        modifyInfo.setProduct(productModule);
        return modifyInfo;
    }

    public GoodsModifyInfoVO modifyInfoPreviewSceneVo(AcceptContext context, SceneModule sceneModule) {
        List<ProductModuleVO> productModule = new ArrayList<>(); //产品信息 ;
        String sceneInstId = context.getSceneVo().getSceneInstId();
        String custId = context.getAcceptRequest().getCustId();
        GoodsModifyInfoVO modifyInfo = new GoodsModifyInfoVO();
        List<KiteProdInst> kiteProdInsts = querySceneInstService.listProdInsts(sceneInstId);
        //获取变动信息
        List<KiteInstChange> instChangesList = querySceneInstService.listInstChanges(sceneInstId);
        List<String> serviceOfferIdList = querySceneInstService //获取页面勾选的操作类型
            .getExtParameterValue(context.getSceneVo().getSceneInstId(), "BUSI_CHANGE_SERVICEOFFERID");

        if (KiteListUtils.isNotEmpty(kiteProdInsts)) {
            kiteProdInsts.forEach(kiteProdInst -> {
                ProductModuleVO productModuleVO = businessChangeService.genProductVO(kiteProdInst.getProdId());
                ProdRoleModuleVO prodRoleVO = businessChangeService.genProductRoleVO(kiteProdInst);
                ProdAttrModuleVO prodAttrModule = new ProdAttrModuleVO();
                for (String serviceOfferId : serviceOfferIdList) {
                    prodAttrModule = businessChangeService
                        .dealProdAttrList(sceneInstId, custId, kiteProdInst, serviceOfferId, prodAttrModule);
                    if (KiteListUtils.isNotEmpty(prodAttrModule.getProdAttrList())) {
                        List<ProdAttrVO> cuccProdAttrList = new ArrayList<>();
                        //将属性设置为预览模式，并设置变动标识
                        prodAttrModule.getProdAttrList().forEach((attr) -> {
                            CuccProdAttrVO cuccProdAttrVO = new CuccProdAttrVO();
                            KiteBeanUtils.copyProperties(attr, cuccProdAttrVO);
                            for (KiteInstChange kiteInstChange : instChangesList) {
                                if (attr.getFieldName().equals(kiteInstChange.getFieldName())) {
                                    cuccProdAttrVO.setNewValue(kiteInstChange.getNewValue());
                                    cuccProdAttrVO.setChangeFlag(true);
                                    cuccProdAttrVO.setOldValue(kiteInstChange.getOldValue());
                                }
                            }
                            cuccProdAttrVO.setAttrValueTypeId("TT");
                            cuccProdAttrList.add(cuccProdAttrVO);
                        });
                        prodAttrModule.setProdAttrList(cuccProdAttrList);
                        prodRoleVO.setProdAttr(prodAttrModule);
                        productModuleVO.getProdRole().add(prodRoleVO);
                        productModule.add(productModuleVO);
                    }
                }
            });
        }
        modifyInfo.setProduct(productModule);
        return modifyInfo;
    }

    private List<CommonAttrVO> getGoodsDisplayInfoAttrs(AcceptContext context, String offerId, String accNum) {

        //只查showType为D的
        List<InstAttrDTO> attrConfigs = queryScenePersonService
            .listGoodsDisplayInfoAttrs(context.getAcceptRequest().getSceneInstId()).getResultObject().stream()
            .filter(instAttrDTO -> LocalKeyConsts.KITE_ATTR_CONFIG_SHOW_TYPE_D.equals(instAttrDTO.getShowType()))
            .collect(Collectors.toList());

        if (KiteListUtils.isEmpty(attrConfigs)) {
            return null;
        }
        List<CommonAttrVO> commonAttrList = AssemblyAttrDtoUtils.assemblyVO(attrConfigs);
        for (CommonAttrVO attrVO : commonAttrList) {

            if ("goods_name".equals(attrVO.getFieldName())) {
                attrVO.setValue(OfferCache.get(offerId).getOfferName());
            }
            else if ("acc_num".equals(attrVO.getFieldName())) {
                attrVO.setValue(accNum);
            }
        }
        //信息需要初始化
        personAttrDealService.initAttrList(commonAttrList);
        return commonAttrList;
    }

    public ServiceOfferInfoModuleVO serviceExecute(AcceptContext context, SceneModule sceneModule) {

        //补充逻辑,进入预览返回录入页面，需要保存已操作列表
        List<String> serviceOfferIdList = querySceneInstService //获取页面勾选的操作类型
            .getExtParameterValue(context.getSceneVo().getSceneInstId(), "BUSI_CHANGE_SERVICEOFFERID");
        ServiceOfferInfoModuleVO serviceOfferInfoModule = new ServiceOfferInfoModuleVO();
        queryServiceOfferInfo(context, serviceOfferInfoModule);
        List<CuccServiceOfferVo> serviceOfferVOs = new ArrayList<>();
        List<CuccServiceOfferTypeVO> serviceOfferTypeVOs = serviceOfferInfoModule.getServiceOfferTypes();
        for (int i = 0; i < serviceOfferTypeVOs.size(); i++) {
            CuccServiceOfferTypeVO cuccServiceOfferTypeVO = serviceOfferTypeVOs.get(i);
            serviceOfferVOs.addAll(cuccServiceOfferTypeVO.getServiceOfferViews());
        }
        //遍历serviceOfferTypeVO.getServiceOfferViews(),如果已经勾选的，则打上标识
        if (KiteListUtils.isNotEmpty(serviceOfferVOs)) {
            serviceOfferVOs.stream().forEach(serviceOfferViews -> {
                if ((KiteListUtils.isNotEmpty(serviceOfferIdList) && serviceOfferIdList
                    .contains(serviceOfferViews.getServiceOfferId())) || (
                    KiteStringUtils.isEqual(serviceOfferViews.getServiceOfferId(), KeyConsts.SERVICE_OFFER_TRANSFER)
                        && serviceOfferIdList.contains(LocalServiceOfferConsts.SERVICE_OFFER_TRANSFER_CUST))) {
                    serviceOfferViews.setCheckedFlag("YY"); //operateType为YY，则表示已经勾选
                }
            });
        }
        return serviceOfferInfoModule;
    }

    private void queryServiceOfferInfo(AcceptContext context, ServiceOfferInfoModuleVO serviceOfferInfoModule) {
        List<ServiceOfferTypeVO> serviceOfferTypeList;
        List<CuccServiceOfferTypeVO> cuccServiceOfferTypeVOS = new ArrayList<>();
        String offerId = context.getAcceptRequest().getOfferId();
        DataResult<List<ServiceOfferTypeVO>> serviceOfferTypeVOList = serviceOfferService
            .listServiceOffers(INSTANCETYPE, offerId, SOURCE, "", "", "", "", KiteWebContext.getContext().getCustId(),
                "", "");
        if (Objects.nonNull(serviceOfferTypeVOList)) {
            serviceOfferTypeList = serviceOfferTypeVOList.getResultObject();
            if (KiteListUtils.isNotEmpty(serviceOfferTypeList)) {
                CuccServiceOfferTypeVO vo = new CuccServiceOfferTypeVO();
                KiteBeanUtils.copyProperties(serviceOfferTypeList.get(0), vo);
                cuccServiceOfferTypeVOS.add(vo);
            }
            serviceOfferInfoModule.setServiceOfferTypes(cuccServiceOfferTypeVOS);
        }
    }

    public ServiceOfferInfoModuleVO serviceReviewSceneVo(AcceptContext context, SceneModule sceneModule) {
        ServiceOfferInfoModuleVO serviceOfferInfoModule = new ServiceOfferInfoModuleVO();
        queryServiceOfferInfo(context, serviceOfferInfoModule);
        List<String> serviceOfferIdList = querySceneInstService //获取页面勾选的操作类型
            .getExtParameterValue(context.getSceneVo().getSceneInstId(), "BUSI_CHANGE_SERVICEOFFERID");
        List<ServiceOfferVO> resultServiceOfferVOList = new ArrayList<>();
        List<CuccServiceOfferTypeVO> serviceOfferTypeVOList = serviceOfferInfoModule.getServiceOfferTypes();
        for (int i = 0; i < serviceOfferTypeVOList.size(); i++) {
            List<CuccServiceOfferVo> serviceOfferVOList = serviceOfferTypeVOList.get(i).getServiceOfferViews();
            if (KiteListUtils.isNotEmpty(serviceOfferIdList)) {
                serviceOfferIdList.stream().forEach(serviceOfferId -> {
                    for (CuccServiceOfferVo serviceOfferVO : serviceOfferVOList) {
                        if (serviceOfferId.equals(serviceOfferVO.getServiceOfferId())) {
                            serviceOfferVO.setCheckedFlag("TT"); //OperateType为TT,代表为预览模式
                        }
                    }
                });
            }
        }
        return serviceOfferInfoModule;
    }

    public TransferInfoVO getTransferDisplayInfoAttrs(String sceneInstId) {

        TransferInfoVO transferInfoVO = new TransferInfoVO();

        //只查showType为D的
        List<InstAttrDTO> attrConfigs = queryScenePersonService
            .listKiteConfigAttrs(sceneInstId, LocalKeyConsts.TRANSFER_DISPLAY_OBJECT_TYPE).getResultObject().stream()
            .filter(instAttrDTO -> LocalKeyConsts.KITE_ATTR_CONFIG_SHOW_TYPE_D.equals(instAttrDTO.getShowType()))
            .collect(Collectors.toList());

        if (KiteListUtils.isEmpty(attrConfigs)) {
            return null;
        }

        List<CommonAttrVO> commonAttrList = AssemblyAttrDtoUtils.assemblyVO(attrConfigs);
        transferInfoVO.setTransferInfoAttr(commonAttrList);
        personAttrDealService.initAttrList(commonAttrList);
        return transferInfoVO;
    }

    public void TransferInfoExecute(AcceptContext context, SceneModule sceneModule, ReCommitInfoVO reCommitInfoVO) {
        String sceneInstId = context.getSceneVo().getSceneInstId();
        //获取所有的操作类型
        List<String> serviceOfferIdList = querySceneInstService //获取页面勾选的操作类型
            .getExtParameterValue(context.getSceneVo().getSceneInstId(), "BUSI_CHANGE_SERVICEOFFERID");
        List<KiteProdInst> kiteProdInsts = querySceneInstService.listProdInsts(sceneInstId);
        if (KiteListUtils.isNotEmpty(kiteProdInsts)) {
            kiteProdInsts.forEach(kiteProdInst -> {
                if (KiteListUtils.isNotEmpty(serviceOfferIdList)) {
                    for (String serviceOfferId : serviceOfferIdList) {
                        //过户信息特殊处理
                        if (LocalServiceOfferConsts.SERVICE_OFFER_TRANSFER_CUST.equals(serviceOfferId)) {
                            TransferInfoVO transferInfoVO = this
                                .getTransferDisplayInfoAttrs(context.getAcceptRequest().getSceneInstId());
                            transferInfoVO.setIsEdit("F");
                            transferInfoVO.setIsShow("T");
                            transferInfoVO.setLayoutPage("TransferenceInfo");
                            transferInfoVO.setModuleName("过户信息");
                            transferInfoVO.setOrderId("3");
                            transferInfoVO.setProdInstId(kiteProdInst.getProdInstId());
                            transferInfoVO.setCustId(context.getAcceptRequest().getCustId());
                            List<TransferenceVO> transferenceVOList = new ArrayList<>();
                            transferenceVOList.add(transferInfoVO);
                            operateSceneInstService
                                .putExtParameter(sceneInstId, "transferProdInst", transferenceVOList);
                            reCommitInfoVO.setTransferInfo(transferInfoVO);
                        }
                    }
                }
            });
        }
    }
}
